package com.qf.ssm.controller;

import com.github.pagehelper.PageInfo;
import com.qf.ssm.constans.ResultCode;
import com.qf.ssm.dto.R;
import com.qf.ssm.exceptions.MybaseException;
import com.qf.ssm.pojo.TbGoodsType;
import com.qf.ssm.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/req")
public class GoodsTypeController {
    private GoodsTypeService goodsTypeService;
    @Autowired
    public void setGoodsTypeService(GoodsTypeService goodsTypeService) {
        this.goodsTypeService = goodsTypeService;
    }
    @GetMapping("/select/{id}")
    public R findById(@PathVariable Long id){
        return R.OK(goodsTypeService.findById(id));
    }
    @PostMapping("/add")
    public R addGoodsType(@RequestBody TbGoodsType goodsType){
        System.out.println(goodsType);
        goodsTypeService.addGoodsType(goodsType);
        return R.OK();
    }
    @GetMapping("/findPage")
    public R findByPage(@RequestParam(defaultValue = "2") int pageSize,@RequestParam(defaultValue = "1") int pageNum){
        PageInfo<TbGoodsType> byPage = goodsTypeService.findByPage(pageSize, pageNum);
        return R.OK(byPage);
    }
    @GetMapping("/delete/{id}")
    public R deleteById(@PathVariable Long id){
        goodsTypeService.deleteById(id);
        return R.getResult(ResultCode.SUCCESS,"删除成功");
    }
}
